package com.example.wacoffee_manage.Mapper;

import com.example.wacoffee_manage.annotation.AutoFill;
import com.example.wacoffee_manage.common.OperationType;
import com.example.wacoffee_manage.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {


    List<User> getAllUsers(User user);

    @AutoFill(OperationType.INSERT)
    @Insert("insert into user (username, gender, phone, image, create_time, creator, update_time, updater) values (#{userName}, #{gender}, #{phone}, #{image}, #{createTime}, #{creator}, #{updateTime}, #{updater}) ")
    void add(User user);

    @Select("select id,user.username,gender,user.phone,user.image from user where id=#{id}")
    User getById(int id);


    @AutoFill(OperationType.UPDATE)
    @Update("update user set username=#{userName},gender=#{gender},phone=#{phone},image=#{image},update_time=#{updateTime},updater=#{updater} where id=#{id}")
    void update(User user);

    @Update("update user set status =0 where id=#{id}")
    void delete(int id);

    @Update("update user set status =1 where id= #{id}")
    void recover(int id);

    void importUserData(List<User> users);
}
